/*******************************************************************************
02_06: Make Table 6: Combined effect of own and partner GGI on non-market work
	for immigrants with immigrant partners

Replication code for "Culture and gender allocation of tasks: source country 
	characteristics and the division of non-market work among US immigrants" in
	Review of Economics of the Household

Authors: Francine Blau, Lawrence Kahn, Matthew Comey, Amanda Eng, Pamela 
	Meyerhofer, and Alexander Willen
	
Date: 10/16/2020

Description: This code generates Table 6

*******************************************************************************/

/*******************************************************************************

I. Preliminaries

*******************************************************************************/

***A. Erase existing output if necessary
cap erase "$tables/Table_6_Panel_A.xls"
cap erase "$tables/Table_6_Panel_A.txt"
cap erase "$tables/Table_6_Panel_B.xls"
cap erase "$tables/Table_6_Panel_B.txt"
cap erase "$tables/Table_6_Panel_C.xls"
cap erase "$tables/Table_6_Panel_C.txt"
cap erase "$tables/Table_6_Panel_D.xls"
cap erase "$tables/Table_6_Panel_D.txt"


***B. Set up labels for summation table
putexcel set "$tables/Table_6_Summation", replace

putexcel A1= "Table 6: Combined effect of own and partner GGI on non-market work for immigrants with immigrant partners, Coefficient Summation", bold

putexcel A4 = "Sum of Own and Partner GGI"
putexcel A7 = "Sum of Own and Partner GGI"

putexcel B2 = "Total Non-Market Work"
putexcel C2 = "Housework"
putexcel D2 = "Childcare"
putexcel E2 = "Total Non-Market Work"
putexcel F2 = "Housework"
putexcel G2 = "Childcare"

putexcel B3 = "Panel A. All Women", italic
putexcel E3 = "Panel B. All Men", italic
putexcel B6 = "Panel C. Women with Children", italic
putexcel E6 = "Panel D. Men with Children", italic


***C. Set control variables
local controls age age2 RACE2 RACE3 RACE4 RACE5 yrsusa1 yrsusa2 cohort70_79 cohort80_89 cohort90_99 cohort00_09 cohort10_17

local fe i.day i.month i.year i.state

local ecp_controls hsdi scol cold young_children middle_children old_children part_age part_age2 part_hsdi part_scol part_cold part_RACE2 part_RACE3 part_RACE4 part_RACE5 part_immig part_secondgen part_yrsusa1 part_yrsusa2 part_cohort70_79 part_cohort80_89 part_cohort90_99 part_cohort00_09 part_cohort10_17

local wife_work wifehours wifehours_vary


/*******************************************************************************

II. Run Regressions

*******************************************************************************/

local maintit  "Table 6: Combined effect of own and partner GGI on non-market work for immigrants with immigrant partners"

**Loop through table panels
foreach panel in A B C D {
	
	*Set sample restrictions and labels
	preserve
	
	if "`panel'" == "A" {
		di "*****Regressing All Immigrant Women*****"
		
		keep if female == 1 & immig==1
		
		local tabtit "`maintit', Panel A. All Women"
		
		local col_$nmw "B"
		local col_$hwork "C"
		local col_$ccare "D"
		
		local row1 = 4
		local row2 = 5
		}
		
	else if "`panel'" == "B" {
		di "*****Regressing All Immigrant Men*****"
		
		keep if female == 0 & immig==1
		
		local tabtit "`maintit', Panel B. All Men"
		
		local col_$nmw "E"
		local col_$hwork "F"
		local col_$ccare "G"
		
		local row1 = 4
		local row2 = 5
		}
		
	else if "`panel'" == "C" {
		di "*****Regressing Immigrant Women with Children*****"
		
		drop if hh_numownkids== 0
		keep if youngc<18 
		keep if female == 1 & immig==1
		
		local tabtit "`maintit', Panel C. Women with Children"
		
		local col_$nmw "B"
		local col_$hwork "C"
		local col_$ccare "D"
		
		local row1 = 7
		local row2 = 8
		}
		
	else if "`panel'" == "D" {
		di "*****Regressing Immigrant Men with Children*****"
		
		drop if hh_numownkids== 0
		keep if youngc<18 
		keep if female == 0 & immig==1
		
		local tabtit "`maintit', Panel D. Men with Children"
		
		local col_$nmw "E"
		local col_$hwork "F"
		local col_$ccare "G"
		
		local row1 = 7
		local row2 = 8
		}


	**Loop through non-market work variables
	foreach var in $nmw $hwork $ccare { 
		
		if "`var'" == "$nmw" {
			local coltit "Total Non-Market Work"
			}
		else if "`var'" == "$hwork" {
			local coltit "Housework"
			}
		else if "`var'" == "$ccare" {
			local coltit "Childcare"
			}


		*Main specification from Tables 3 and 4 
		reg `var' GGI part_GGI GDP fertility part_GDP part_fertility `controls' `ecp_controls' `fe' [aw=newwt] if part_immig == 1, robust cluster(bpl) 
		quietly summ `var' [aw=newwt] if e(sample)==1   
		outreg2 using "$tables/Table_6_Panel_`panel'.xls", keep(GGI part_GGI) append ctitle(`coltit') addstat(Mean, r(mean)) label title("`tabtit'") nocons
			
		lincom part_GGI + GGI
		local ste = r(se)
		
		getstars r(estimate) r(se) r(df)
		
		putexcel `col_`var''`row1' = (r(eststar))
		putexcel `col_`var''`row2' = `ste', nformat("(0.000)")
		
		local c=`c'+1
			
			}
	restore
	
	}
	
***Erase text files
cap erase "$tables/Table_6_Panel_A.txt"
cap erase "$tables/Table_6_Panel_B.txt"
cap erase "$tables/Table_6_Panel_C.txt"
cap erase "$tables/Table_6_Panel_D.txt"
